package com.vegetable.common.base;

import com.vegetable.common.utils.BankCardRedisService;
import com.vegetable.modules.entity.baseData.BankCard;
import com.vegetable.modules.service.baseData.IBankCardService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
public class BankCardCacheInitializer implements CommandLineRunner {

    @Autowired
    private IBankCardService bankCardService;

    @Autowired
    private BankCardRedisService bankCardRedisService;

    @Override
    public void run(String... args) throws Exception {
        log.info("开始初始化bankCard缓存...");
        
        try {
            // 查询所有启用的bankCard记录
            List<BankCard> bankCardList = bankCardService.list();
            log.info("查询到{}条bankCard记录", bankCardList.size());
            
            // 将bankNo信息存入Redis缓存
//            bankCardRedisService.cacheBankCardList(bankCardList);
            log.info("bankCard缓存初始化完成");
        } catch (Exception e) {
            log.error("初始化bankCard缓存失败", e);
        }
    }
}